package com.ruge.core.tool;

import com.ruge.core.domain.BaseQuery;
import org.springframework.data.domain.Pageable;

/**
 * @author ruge.wu
 * @since 2022/06/08 16:44:00
 */
public class PageTool {

    public static Pageable getPageable(BaseQuery baseQuery) {
        return org.springframework.data.domain.PageRequest.of(baseQuery.getPage(), baseQuery.getLimit());
    }

    public static Integer getMysqlStart(BaseQuery baseQuery) {
        return baseQuery.getPage() * baseQuery.getLimit();
    }

    public static Integer getMysqlEnd(BaseQuery baseQuery) {
        return (baseQuery.getPage() + 1) * baseQuery.getLimit();
    }

    public static Integer getOracleStart(BaseQuery baseQuery) {
        return baseQuery.getPage() * baseQuery.getLimit();
    }

    public static Integer getOracleEnd(BaseQuery baseQuery) {
        return baseQuery.getPage() * baseQuery.getLimit();
    }
}
